package serverDB_classes;


import org.hibernate.Session;

/**
 * manage Dir instance at the data base
 * @author Yoav
 *
 */
public class DirManager {

	/**
	 * create a new dir in data base
	 * @param session - open session to data base
	 * @param dirPath - dir's path
	 * @return created dir
	 */
	public Dir createDir(Session session,String dirPath) {
		Dir dir=new Dir();
		dir.setDirPath(dirPath);
		save(session,dir);
		return dir;
	}

	/*
	 * save new dir in data base 
	 * @param session open session to data base
	 * @param dir the new dir instance
	 */
	private void save(Session session, Dir dir) {
		session.save(dir);
		session.flush();
		
	}

	/**
	 * delete a dir from data base
	 * @param session - open session to data base
	 * @param dir - dir to delete
	 */
	public void delete(Session session,Dir dir) {
		  session.delete(dir);
		  session.flush();
	}
	/**
	 * update dir in data base
	 * @param session - open session to data base
	 * @param dir - dir to update
	 */
	public void update(Session session, Dir dir) {
		session.update(dir);
		session.flush();
		
	}

}
